<template>
  <div class="page-main" v-title data-title="清消方案主数据">
    <home-nav :userData="userinfo"></home-nav>
    <div class="banner"><span>清消方案主数据</span></div>
    <div class="container">
      <div class="container-bg">
        <div class="header">
          <a-row type="flex" justify="space-between" align="middle">
            <a-col>
              <a-button class="hte-btn add-btn" type="primary" icon="plus" @click="handAction('add')">新增</a-button>
              <a-button class="hte-btn" @click="handAction('upd')">编辑</a-button>
              <!-- <a-button class="hte-btn" @click="handlePostExportXls('清消方案主数据')">导出</a-button> -->
              <a-button class="hte-btn" type="danger" @click="handAction('del')">删除</a-button>
              <a-button class="hte-btn" @click="refresh">刷新</a-button>
            </a-col>
            <a-col>
              <a-radio-group v-model="radioType" button-style="solid" @change="handRadio">
                <a-radio-button value="/clearJy/method/list">清洗方式维护</a-radio-button>
                <!-- <a-radio-button value="/clearJy/topMater/list">顶料量维护</a-radio-button>
                <a-radio-button value="/clearJy/rule/list">转规时长维护</a-radio-button> -->
              </a-radio-group>
            </a-col>
            <a-col class="input-ground">
              <a-input-group compact>
                <a-select v-model="searchField" @change="changeKeywordType">
                  <a-select-option value="planNoStr"> 方案编号 </a-select-option>
                  <a-select-option value="planName"> 方案名称 </a-select-option>
                </a-select>
                <a-input-search
                  v-if="searchField == 'planNoStr'"
                  v-model="queryParam.planNoStr"
                  @search="doSearch"
                  allowClear
                  placeholder="请输入关键词检索"
                />
                <a-input-search
                  v-if="searchField == 'planName'"
                  v-model="queryParam.planName"
                  @search="doSearch"
                  allowClear
                  placeholder="请输入关键词检索"
                />
              </a-input-group>
              <a-button class="hte-btn del-btn" @click="visibleModel = true">高级查询</a-button>
            </a-col>
          </a-row>
        </div>
        <div class="content">
          <a-table
            class="hte-table-content"
            :scroll="{ x: 1020 }"
            :columns="columns"
            :data-source="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            rowKey="id"
            size="middle"
            @change="handleTableChange"
          >
            <template slot="swicth" slot-scope="text">
              <span>{{ text ? '是' : '否' }}</span>
            </template>
            <template slot="planNo" slot-scope="text, record">
              <span class="clickspan" @click="handAction('upd', record.id)">{{ text }}</span>
            </template>
          </a-table>
        </div>
      </div>
    </div>
    <a-back-top class="backtodom" />
    <!-- 高级查询 -->
    <advanced-search
      :dataForm.sync="queryParam"
      :visible="visibleModel"
      ref="advanced"
      :formCol="queryParamCol"
      @ok="callBackResult"
      @reset="resetResulte"
      @close="closeResulte"
    >
    </advanced-search>
    <!-- 新增/修改 -->
    <ClearAddModal :washType="washType" ref="burdenAdd" @ok="doSearch"></ClearAddModal>
  </div>
</template>
<script>
import Vue from 'vue'
import { getAction, postAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListSearchMixin'
import { USER_INFO } from '@/store/mutation-types'
import { ClearLibMixin } from '@/mixins/ClearLibMixin'
import {codeInfoList} from '@/api/codeInfo'
export default {
  name: 'BurdenList',
  mixins: [ClearLibMixin,JeecgListMixin],
  components: {
    HomeNav: () => import('@/components/layouts/HomeNav'),
    AdvancedSearch: () => import('@/components/tools/AdvancedSearch'),
    ClearAddModal: () => import('./clearAddModal'),
  },
  data() {
    return {
      disableMixinCreated:true,
      userinfo: {
        info: this.$store.getters.userInfo,
        module: 'ClearList',
      },
      radioType: '',
      currUser: Vue.ls.get(USER_INFO).username,
      columns: [
        {
          title: '方案编号',
          dataIndex: 'planNoStr',
          width: 120,
          align: 'center',
          scopedSlots: { customRender: 'planNo' },
        },
        { title: '清洗方案', dataIndex: 'wayName', width: 180, align: 'center' },
        { title: '方案名称', dataIndex: 'planName', width: 180, align: 'center', ellipsis: true },
        { title: '方案描述', dataIndex: 'planDesc', width: 180, align: 'center', ellipsis: true },
        { title: '品种配料关系', dataIndex: 'matRelateName', width: 280, align: 'center',ellipsis: true, 
          // customRender: (text, record) => {
          //   if (text == 1) {
          //     return '下品种<完全包含>上品种';
          //   } else if (text == 2) {
          //     return '下品种<不完全包含>上品种';
          //   }
          //   return text;
          // }
        },
        { title: '过敏原特性', dataIndex: 'matFeatureName', width: 180, align: 'center',ellipsis: true},
        { title: '特殊属性关系', dataIndex: 'specialAttributesName', width: 280, align: 'center',ellipsis: true},
        { title: '有机属性', dataIndex: 'organic', width: 80, align: 'center',ellipsis: true, scopedSlots: { customRender: 'swicth' },},
        { title: '加严属性', dataIndex: 'stricture', width: 80, align: 'center',ellipsis: true, scopedSlots: { customRender: 'swicth' },},
      ],
      url: {
        list: '/hteWashPlan/page', // 搜索
        delBatch: '/hteWashPlan/delBatch', // 删除
        exportXlsUrl: '/hteLibMediaOrder/export', // 导出
        addBatch: '', // 导入
      },
      // 高级查询
      visibleModel: false,
      searchField: 'planNoStr',
      queryParam: {
        orderNo: '',
        orderName: '',
      },
      queryParamCol: [
        { type: 'input', model: 'planNoStr', label: '方案编号' },
        { type: 'input', model: 'planName', label: '方案名称' },
      ],
      // 导入
      exportXlsTemplateUrl: 'templates/excel/brandSimilitudeGroupTemplate.xlsx', //导入模板
      excelVisible: false,
      excelConfirmLoading: false,
      columnsExcel: [],
      dict:{},
    }
  },
  mounted() {
    this.columnsExcel = this.columns.filter(item=>{
      return ['清洗方案', '方案名称', '方案描述', '品种配料关系', '残余配料特性'].includes(item.title)
    })
  },
  created(){
     this.loadData(1);
     this.initDics()
  },
  methods: {
     initDics(){
        
    },
    refresh() {
      this.loadData()
    },
    doSearch() {
      this.loadData(1)
    },
    changeKeywordType() {
      if (this.searchField == 'planNoStr') {
        this.$set(this.queryParam, 'planName', '')
      } else {
        this.$set(this.queryParam, 'planNoStr', '')
      }
    },
    handRadio(){      
      let routeUrl = this.$router.resolve({
        path: this.radioType
      });
      window.open(routeUrl.href, '_blank');
    },
    /**
     * 高级搜索
     */
    callBackResult() {
      this.visibleModel = false
      this.doSearch()
    },
    closeResulte() {
      this.visibleModel = false
    },
    resetResulte() {
      this.queryParam = {}
    },
    /**
     * 操作
     */
    handAction(type, id) {
      switch (type) {
        case 'add':
          // 新增
          this.$refs.burdenAdd.showVisible()
          break
        case 'del':
          // 删除，可多选
          const that = this
          if (this.selectedRowKeys.length == 0) {
            this.$message.warning('请选择至少一条数据！')
            return
          }
          this.$confirm({
            title: '确认删除',
            content: '请确认是否删除此信息?',
            onOk: function () {
              postAction(that.url.delBatch, that.selectedRowKeys).then((res) => {
                if (res.code == 200) {
                  that.$message.success('删除成功')
                  that.loadData();
                } else {
                  that.$message.warning('删除失败:' + res.message)
                }
              })
            },
          })
          break
        case 'upd':
          // 修改
          if (!id && this.selectedRowKeys.length != 1) {
            this.$message.warning('请选择一条数据！')
            return
          }
          this.$refs.burdenAdd.showVisible(id || this.selectionRows[0].id)
          break
        default:
          break
      }
    },
     
  },
}
</script>

<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
@import '~@views/library/clearSoln/index.less';
</style>
